package com.itlong.cloud.rabbitmq.config;

import com.itlong.cloud.constants.RabbitMQConstant;
import com.itlong.cloud.utils.rabbitMQ.BaseConfig;
import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.Queue;
import org.springframework.amqp.core.TopicExchange;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.HashMap;
import java.util.Map;

/**
 * <desc>
 *      用户服务消息队列配置。
 * </desc>
 *
 * @createDate 2017/08/29
 */
@Configuration
public class RabbitConfig extends BaseConfig {

    //声明XXXX队列，true表示持久化该队列
    @Bean
    public Queue userMyRabbit1() {
        Queue queue = new Queue(RabbitMQConstant.RABBITMQ_USER_SAVE_USER_INFO_QUEUE1,true, false, false, null);
        return queue;
    }

    //死信设置只能配置一次， 下一次修改不会生效反而会报错
    @Bean
    public Queue queueYewu() {
        Map<String, Object> map = new HashMap();
        map.put("x-message-ttl", RabbitMQConstant.QUEUE_TTL);
        map.put("x-dead-letter-exchange", RabbitMQConstant.DEAD_LETTER_EXCHANGE);
        map.put("x-dead-letter-routing-key", RabbitMQConstant.MAIL_QUEUE_FAIL);
        Queue queue = new Queue("queueDed",true, false, false, map);
        return queue;
    }

    //项目启用/禁用云对讲时，通知用户服务更新住户项目信息中的SIP
    @Bean
    public Queue updateHouseHoldProjectSip() {
        Map<String, Object> map = new HashMap();
        map.put("x-message-ttl", RabbitMQConstant.QUEUE_TTL);
        map.put("x-dead-letter-exchange", RabbitMQConstant.DEAD_LETTER_EXCHANGE);
        map.put("x-dead-letter-routing-key", RabbitMQConstant.MAIL_QUEUE_FAIL);
        Queue queue = new Queue(RabbitMQConstant.RABBITMQ_PROJECT_SMART_COMMUNITY_STATUS_QUEUE, true, false, false, map);
        return queue;
    }

    //修改亲属的开门密码queue
    @Bean
    public Queue updateFamilyOpenPwd() {
        Map<String, Object> map = new HashMap();
        map.put("x-message-ttl", RabbitMQConstant.QUEUE_TTL);
        map.put("x-dead-letter-exchange", RabbitMQConstant.DEAD_LETTER_EXCHANGE);
        map.put("x-dead-letter-routing-key", RabbitMQConstant.MAIL_QUEUE_FAIL);
        Queue queue = new Queue(RabbitMQConstant.RABBITMQ_UPDATE_FAMILY_OPENPWD_QUEUE, true, false, false, map);
        return queue;
    }

    @Bean
    public Queue userMyRabbit2() {
        return new Queue(RabbitMQConstant.RABBITMQ_USER_SAVE_USER_INFO_QUEUE2, true);
    }

    //SDK添加独立开发者Quene
    @Bean
    public Queue saveDeveloper() {
        Map<String, Object> map = new HashMap();
        map.put("x-message-ttl", RabbitMQConstant.QUEUE_TTL);
        map.put("x-dead-letter-exchange", RabbitMQConstant.DEAD_LETTER_EXCHANGE);
        map.put("x-dead-letter-routing-key", RabbitMQConstant.MAIL_QUEUE_FAIL);
        Queue queue = new Queue(RabbitMQConstant.RAABITMQ_SDK_SAVEDEVELOPER_QUENUE, true, false, false, map);
        return queue;
    }

    @Bean
    public Queue delCache() {
        Map<String, Object> map = new HashMap();
        map.put("x-message-ttl", RabbitMQConstant.QUEUE_TTL);
        map.put("x-dead-letter-exchange", RabbitMQConstant.DEAD_LETTER_EXCHANGE);
        map.put("x-dead-letter-routing-key", RabbitMQConstant.MAIL_QUEUE_FAIL);
        Queue queue = new Queue(RabbitMQConstant.RABBITMQ_DELETE_CACHE_QUEUE,
                true, false, false, map);
        return queue;
    }

    @Bean
    public Queue cloudTalkSDKUserSaveDeviceAuthInfo() {
        Map<String, Object> map = new HashMap();
        map.put("x-message-ttl", RabbitMQConstant.QUEUE_TTL);
        map.put("x-dead-letter-exchange", RabbitMQConstant.DEAD_LETTER_EXCHANGE);
        map.put("x-dead-letter-routing-key", RabbitMQConstant.MAIL_QUEUE_FAIL);
        Queue queue = new Queue(RabbitMQConstant.RABBITMQ_CLOUD_TALK_SDK_USER_SAVE_DEVICE_AUTH_INFO_QUEUE,
                true, false, false, map);
        return queue;
    }

    @Bean
    public Queue createLykzCloudIntercomAccountInfo() {
        Map<String, Object> map = new HashMap();
        map.put("x-message-ttl", RabbitMQConstant.QUEUE_TTL);
        map.put("x-dead-letter-exchange", RabbitMQConstant.DEAD_LETTER_EXCHANGE);
        map.put("x-dead-letter-routing-key", RabbitMQConstant.MAIL_QUEUE_FAIL);
        Queue queue = new Queue(RabbitMQConstant.RABBITMQ_CREATE_LYKZ_CLOUD_INTERCOM_ACCOUNT_QUEUE,
                true, false, false, map);
        return queue;
    }

    @Bean
    public Queue projectCloudTalkSdkCreateLykzAccount() {
        Map<String, Object> map = new HashMap();
        map.put("x-message-ttl", RabbitMQConstant.QUEUE_TTL);
        map.put("x-dead-letter-exchange", RabbitMQConstant.DEAD_LETTER_EXCHANGE);
        map.put("x-dead-letter-routing-key", RabbitMQConstant.MAIL_QUEUE_FAIL);
        Queue queue = new Queue(RabbitMQConstant.RABBITMQ_PROJECT_CLOUD_TALK_SDK_CREATE_LYKZ_ACCOUNT_QUEUE,
                true, false, false, map);
        return queue;
    }

    //声明交互器
    @Bean
    TopicExchange topicExchange() {
        return new TopicExchange(RabbitMQConstant.RABBITMQ_USER_EXCHANGE,true,false);
    }

    //绑定
    @Bean
    public Binding binding1() {
        return BindingBuilder.bind(queueYewu()).to(topicExchange()).with(RabbitMQConstant.RABBITMQ_USER_SAVE_USER_INFO_ROUTING_KEY1);
    }

    @Bean
    public Binding binding2() {
        return BindingBuilder.bind(userMyRabbit2()).to(topicExchange()).with(RabbitMQConstant.RABBITMQ_USER_SAVE_USER_INFO_ROUTING_KEY2);
    }

    @Bean Binding saveDeveloperBinding() {
        return BindingBuilder.bind(saveDeveloper()).to(topicExchange()).with(RabbitMQConstant.RAABITMQ_SDK_SAVEDEVELOPER_KEY);
    }

    @Bean Binding updateHouseHoldProjectSipBinding() {
        return BindingBuilder.bind(updateHouseHoldProjectSip()).to(topicExchange()).with(RabbitMQConstant.RABBITMQ_PROJECT_SMART_COMMUNITY_STATUS_KEY);
    }

    @Bean
    public Binding updateFamilyOpenPwdBinding(){
        return BindingBuilder.bind(updateFamilyOpenPwd()).to(topicExchange()).with(RabbitMQConstant.RABBITMQ_UPDATE_FAMILY_OPENPWD_KEY);
    }
    @Bean
    public Binding deleteCacheBinding(){
        return BindingBuilder.bind(delCache()).to(topicExchange()).with(RabbitMQConstant.RABBITMQ_DELETE_CACHE_KEY);
    }
    @Bean
    public Binding cloudTalkSDKUserSaveDeviceAuthInfoBinding(){
        return BindingBuilder.bind(cloudTalkSDKUserSaveDeviceAuthInfo()).to(topicExchange()).with(RabbitMQConstant.RABBITMQ_CLOUD_TALK_SDK_USER_SAVE_DEVICE_AUTH_INFO_ROUTING_KEY);
    }
    @Bean
    public Binding createLykzCloudIntercomAccountInfoBinding(){
        return BindingBuilder.bind(createLykzCloudIntercomAccountInfo()).to(topicExchange()).with(RabbitMQConstant.RABBITMQ_CREATE_LYKZ_CLOUD_INTERCOM_ACCOUNT_KEY);
    }
    @Bean
    public Binding projectCloudTalkSdkCreateLykzAccountBinding(){
        return BindingBuilder.bind(projectCloudTalkSdkCreateLykzAccount()).to(topicExchange()).with(RabbitMQConstant.RABBITMQ_PROJECT_CLOUD_TALK_SDK_CREATE_LYKZ_ACCOUNT_KEY);
    }
    public static void main(String[] args) {
    }
}
